public class Solution {
    public int[] diStringMatch(String s) {
        int len = s.length();
        int numI = 0, numD = len;

        int[] ret = new int[len + 1];

        for (int i = 0; i < len; i++) {
            if (s.charAt(i) == 'I') {
                ret[i] = numI++;
            } else {
                ret[i] = numD--;
            }
        }

        ret[len] = s.charAt(len - 1) == 'I' ? numI : numD;
        return ret;
    }
}
